﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace IceZero.Business.Models
{

    public class IceZeroBusinessException : ApplicationException
    {
        /// <summary>
        /// 错误编码
        /// </summary>
        public string Code { get; set; }

        public IceZeroBusinessException(string message) : base(message)
        {
            this.Code = ExceptionCode.CError;
        }

        public IceZeroBusinessException(string message, string code) : base(message)
        {
            this.Code = code;
        }

        public IceZeroBusinessException(string message, string code, Exception innerException) : base(message, innerException)
        {
            this.Code = code;
        }
        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        public override string ToString()
        {
            return $"Exception Source:{this.Source}\r\nTarget Site:{this.TargetSite}\r\nCode:{this.Code}\r\nMessage:{this.Message}\r\nStack Trace:{this.StackTrace}";
        }

        /// <summary>
        /// 获取错误信息对象，可以用作返回值
        /// </summary>
        /// <returns></returns>
        public IceZeroExceptionResult GetResult()
        {
            return new IceZeroExceptionResult()
            {
                Code = this.Code,
                Message = this.Message,
                ExceptionSource = $"{this.TargetSite.DeclaringType.FullName}.{this.TargetSite.Name}",
                StackTrace=this.StackTrace
            };
        }
    }
}
